package com.lenovo.smarttraffic.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CalendarView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lenovo.smarttraffic.R;

import java.util.ArrayList;
import java.util.List;

public class Activity_4_3 extends AppCompatActivity {
    private ImageView icon;
    private TextView title;
    private CalendarView a_4_3_cv1;
    private TextView a_4_3_tv1;
    private TextView a_4_3_tv2;
    ArrayList arrayList;
    List<String> stringList = new ArrayList<>();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_4_3);
        initView();
        arrayList = getIntent().getStringArrayListExtra("data");
    }

    private void initView() {
        icon = (ImageView) findViewById(R.id.icon);
        title = (TextView) findViewById(R.id.title);
        a_4_3_cv1 = findViewById(R.id.a_4_3_cv1);
        a_4_3_tv1 = (TextView) findViewById(R.id.a_4_3_tv1);
        a_4_3_tv2 = (TextView) findViewById(R.id.a_4_3_tv2);

        icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        title.setText("定制班车");
        a_4_3_tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(a_4_3_tv1.getText().toString().equals("")){
                    Toast.makeText(Activity_4_3.this, "请选择日期", Toast.LENGTH_SHORT).show();
                    return;
                }
                arrayList.add(a_4_3_tv1.getText().toString());
                startActivity(new Intent(Activity_4_3.this,Activity_4_4.class).putStringArrayListExtra("data",arrayList));
            }
        });

        a_4_3_cv1.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
            @Override
            public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
                a_4_3_tv1.setText("");
                Log.i("calendar",i+"-"+i1+"-"+i2);
                String date = i+"-"+i1+"-"+i2;
                int STATU = 0;
                for(int a=0;a<stringList.size();a++){
                    if(stringList.get(a).equals(date)){
                        stringList.remove(date);
                        STATU = 1;
                    }
                }

                if(STATU==0){
                    stringList.add(date);
                }

                for(int a=0;a<stringList.size();a++){
                    a_4_3_tv1.append(stringList.get(a)+"\n");
                }
            }
        });

    }

}
